//
//  CPSVideoEditDemo2Controller.m
//  CollTest
//
//  Created by codew on 1/20/22.
//

#import "CPSVideoEditDemo2Controller.h"
#import <MobileCoreServices/UTCoreTypes.h>
#import "CPSVEP_PhotoViewController.h"
#import "CPSVEP_CustomCameraViewController.h"
#import "HXCustomAssetModel.h"
#import "HXPhotoManager.h"
#import "HXPhotoSubViewCell.h"
#import "HXPhotoView.h"
#import "UIViewController+HXExtension.h"
#import <SystemConfiguration/CaptiveNetwork.h>

#import "HXPhotoViewController.h"
@interface CPSVideoEditDemo2Controller ()

@property (strong, nonatomic) HXPhotoManager *photoManager;
//@property (weak, nonatomic) IBOutlet CPSTestButton *btnMore;
//@property (weak, nonatomic) IBOutlet CPSTestButton *btnMore2;
@end

@implementation CPSVideoEditDemo2Controller

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    
//    self.btnMore.imagePosition = CPSTestButtonImagePositionRight;
//    self.btnMore.spacingBetweenImageAndTitle = 5;
//    
//    self.btnMore2.imagePosition = CPSTestButtonImagePositionRight;
//    self.btnMore2.spacingBetweenImageAndTitle = 5;
//    
}


- (IBAction)btnCLikc:(id)sender {
    
    self.photoManager.type = HXPhotoManagerSelectedTypeVideo;
    self.photoManager.configuration.clarityScale = 1.2;
    
    //----------------------------------------------------------------------
    self.photoManager.configuration.themeColor = self.view.tintColor;
    self.photoManager.configuration.cellSelectedTitleColor = nil;
    
    //----------------------------------------------------------------------
    self.photoManager.configuration.navBarBackgroudColor = nil;
    self.photoManager.configuration.statusBarStyle = UIStatusBarStyleDefault;
    self.photoManager.configuration.cellSelectedBgColor = nil;
    self.photoManager.configuration.selectedTitleColor = nil;
    //----------------------------------------------------------------------
    self.photoManager.configuration.navigationTitleColor = nil;
    //----------------------------------------------------------------------
    self.photoManager.configuration.hideOriginalBtn = YES;
    self.photoManager.configuration.photoMaxNum = 1;
    self.photoManager.configuration.videoMaxNum = 1;
    self.photoManager.configuration.maxNum = 1;
    self.photoManager.configuration.rowCount = 4;
    self.photoManager.configuration.saveSystemAblum = NO;
    self.photoManager.configuration.showDateSectionHeader = NO;
    self.photoManager.configuration.reverseDate = NO;
    self.photoManager.configuration.navigationTitleSynchColor = NO;
    self.photoManager.configuration.replaceCameraViewController = NO;
    self.photoManager.configuration.openCamera = NO;
    self.photoManager.configuration.albumShowMode = 1;
    self.photoManager.configuration.photoCanEdit = YES;
    self.photoManager.configuration.videoCanEdit = YES;
    self.photoManager.configuration.creationDateSort = YES;
    //----------------------------------------------------------------------
//    [self requestModel];
    
    CPSVEP_PhotoViewController *vc = [[CPSVEP_PhotoViewController alloc] init];
    vc.manager = self.photoManager;
    
    
    HXCustomNavigationController *nav = [[HXCustomNavigationController alloc] initWithRootViewController:vc];
    nav.modalPresentationStyle = UIModalPresentationOverFullScreen;
    nav.modalPresentationCapturesStatusBarAppearance = YES;
    if (nav) {
        nav.hx_delegate = nil;
        nav.manager = self.photoManager;
//        [nav requestAuthorization];
        nav.doneBlock = nil;
        nav.cancelBlock = nil;
        vc.doneBlock = nav.doneBlock;
        vc.cancelBlock = nav.cancelBlock;
        vc.delegate = nav;
    }
    
    nav.modalPresentationStyle = UIModalPresentationOverFullScreen;
    nav.modalPresentationCapturesStatusBarAppearance = YES;
    [self presentViewController:nav animated:YES completion:nil];
                
}




- (HXPhotoManager *)photoManager
{
    if (!_photoManager) {
        _photoManager = [[HXPhotoManager alloc] initWithType:HXPhotoManagerSelectedTypePhotoAndVideo];
        _photoManager.configuration.videoMaxNum = 5;
        _photoManager.configuration.deleteTemporaryPhoto = NO;
        _photoManager.configuration.lookLivePhoto = YES;
        _photoManager.configuration.saveSystemAblum = YES;
        _photoManager.configuration.selectTogether = YES;
        _photoManager.configuration.creationDateSort = YES;
//        _photoManager.configuration.supportRotation = NO;
//        _photoManager.configuration.cameraCellShowPreview = NO;
//        _photoManager.configuration.themeColor = [UIColor redColor];
        _photoManager.configuration.navigationBar = ^(UINavigationBar *navigationBar, UIViewController *viewController) {
//            [navigationBar setBackgroundImage:[UIImage imageNamed:@"APPCityPlayer_bannerGame"] forBarMetrics:UIBarMetricsDefault];
//            navigationBar.barTintColor = [UIColor redColor];
        };
//        _photoManager.configuration.sectionHeaderTranslucent = NO;
//        _photoManager.configuration.navBarBackgroudColor = [UIColor redColor];
//        _photoManager.configuration.sectionHeaderSuspensionBgColor = [UIColor redColor];
//        _photoManager.configuration.sectionHeaderSuspensionTitleColor = [UIColor whiteColor];
//        _photoManager.configuration.statusBarStyle = UIStatusBarStyleLightContent;
//        _photoManager.configuration.selectedTitleColor = [UIColor redColor];
        
//        _photoManager.configuration.requestImageAfterFinishingSelection = YES;
        
        __weak typeof(self) weakSelf = self;
        _photoManager.configuration.photoListBottomView = ^(HXPhotoBottomView *bottomView) {
            if (weakSelf.photoManager.configuration.photoStyle != HXPhotoStyleDark) {
//                bottomView.bgView.barTintColor = weakSelf.bottomViewBgColor;
            }
        };
        _photoManager.configuration.previewBottomView = ^(HXPhotoPreviewBottomView *bottomView) {
            if (weakSelf.photoManager.configuration.photoStyle != HXPhotoStyleDark) {
//                bottomView.bgView.barTintColor = weakSelf.bottomViewBgColor;
//                bottomView.tipView.barTintColor = bottomView.bgView.barTintColor;
            }
        };
        _photoManager.configuration.albumListCollectionView = ^(UICollectionView *collectionView) {
//            NSSLog(@"albumList:%@",collectionView);
        };
        _photoManager.configuration.photoListCollectionView = ^(UICollectionView *collectionView) {
//            NSSLog(@"photoList:%@",collectionView);
        };
        _photoManager.configuration.previewCollectionView = ^(UICollectionView *collectionView) {
//            NSSLog(@"preview:%@",collectionView);
        };
//        _photoManager.configuration.movableCropBox = YES;
//        _photoManager.configuration.movableCropBoxEditSize = YES;
//        _photoManager.configuration.movableCropBoxCustomRatio = CGPointMake(1, 1);
        
        // 使用自定义的相机  这里拿系统相机做示例
        _photoManager.configuration.shouldUseCamera = ^(UIViewController *viewController, HXPhotoConfigurationCameraType cameraType, HXPhotoManager *photoManager) {
            
            // 这里拿使用系统相机做例子
            UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
            imagePickerController.delegate = (id)weakSelf;
            imagePickerController.allowsEditing = NO;
            NSString *requiredMediaTypeImage = ( NSString *)kUTTypeImage;
            NSString *requiredMediaTypeMovie = ( NSString *)kUTTypeMovie;
            NSArray *arrMediaTypes;
            if (cameraType == HXPhotoConfigurationCameraTypePhoto) {
                arrMediaTypes=[NSArray arrayWithObjects:requiredMediaTypeImage,nil];
            }else if (cameraType == HXPhotoConfigurationCameraTypeVideo) {
                arrMediaTypes=[NSArray arrayWithObjects:requiredMediaTypeMovie,nil];
            }else {
                arrMediaTypes=[NSArray arrayWithObjects:requiredMediaTypeImage, requiredMediaTypeMovie,nil];
            }
            [imagePickerController setMediaTypes:arrMediaTypes];
            // 设置录制视频的质量
            [imagePickerController setVideoQuality:UIImagePickerControllerQualityTypeHigh];
            //设置最长摄像时间
            [imagePickerController setVideoMaximumDuration:60.f];
            imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
            imagePickerController.navigationController.navigationBar.tintColor = [UIColor whiteColor];
            imagePickerController.modalPresentationStyle=UIModalPresentationOverCurrentContext;
            [viewController presentViewController:imagePickerController animated:YES completion:nil];
        };
//        _photoManager.shouldSelectModel = ^NSString *(HXPhotoModel *model) {
//            // 如果return nil 则会走默认的判断是否达到最大值
//            //return nil;
//            return @"Demo1 116 - 120 行注释掉就能选啦~\(≧▽≦)/~";
//        };
        _photoManager.configuration.videoCanEdit = NO;
        _photoManager.configuration.photoCanEdit = NO;
    }
    return _photoManager;
}

@end
